package at.jku.ase.communication.parsers;

import at.jku.ase.communication.SessionObject;
import at.jku.ase.utils.XMLUtils;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class SignatureParser extends ComponentParser {
    public SignatureParser(final SessionObject session, final XMLResponse action) {
        super(session, action);
    }

    @Override
    protected Object processRequest(XMLStreamReader reader) throws XMLStreamException {
        if (reader.next() == XMLStreamConstants.CHARACTERS) {
            System.out.println("Parsing signature");
            String signString= reader.getText();
            byte[] signature = XMLUtils.base64ToByteArray(signString);
            this.getSession().setSignature(signature);
        }
        return null;
    }
}
